import React from 'react';
import { Table } from 'antd';
import { ArchiveTabType, TableColumn } from '@/types/prefiling/onlineCollecting';

interface ArchiveTableProps {
  type: ArchiveTabType;
  columns: TableColumn[];
  data: {
    list: any[];
    total: number;
  };
  loading: boolean;
  selectedRows: React.Key[];
  onSelectChange: (keys: React.Key[]) => void;
  onTableChange: (params: any) => void;
  pagination: {
    current: number;
    pageSize: number;
    total: number;
  };
  dynamicHeight?: number;
}

const ArchiveTable: React.FC<ArchiveTableProps> = ({
  columns,
  data,
  loading,
  selectedRows,
  onSelectChange,
  onTableChange,
  pagination,
  dynamicHeight
}) => {
  // 计算表格最小宽度
  const tableMinWidth = columns.reduce((sum, col) => sum + (col.width || 150), 0);

  // 计算表格高度
  const tableHeight = dynamicHeight 
    ? `calc(100vh - ${dynamicHeight}px)`
    : 'calc(100vh - 350px)'; // 默认值
  return (
    <Table
      rowKey="id"
      columns={columns}
      dataSource={data.list}
      loading={loading}
      size="small"
      bordered
      rowSelection={{
        selectedRowKeys: selectedRows,
        onChange: onSelectChange,
      }}
      pagination={{
        ...pagination,
        showSizeChanger: true,
        showQuickJumper: true,
        pageSizeOptions: ['10', '20', '50', '100'],
        showTotal: (total) => `共 ${total} 条`,
      }}
      onChange={onTableChange}
      scroll={{
        x: tableMinWidth,
        y: tableHeight
      }}
      locale={{
        emptyText: (
          <div style={{
            minWidth: tableMinWidth,
            lineHeight: '200px',
            textAlign: 'center'
          }}>
            暂无数据
          </div>
        )
      }}
    />
  );
};

export default ArchiveTable;